{% extends 'base.html' %}
{% block title %}
    <a class="navbar-brand" href="{{ url_for('probation') }}"> 试用期员工 试用期信息 </a>
{% endblock %}
{% block write %}
    {% if current_user.has_role('Admin') or current_user.has_role('Root') %}
    <li>
    <a href="{{ url_for('formal') }}" class="btn btn-simple btn-info btn-icon like" data-toggle="dropdown">
        转正员工 试用期信息
    </a>
    </li>
    {% endif %}
{% endblock %}
{% block content %}
    {# 使用 length 过滤器获取 staffs 变量的长度 #}
    {% if current_user.has_role('Admin') or current_user.has_role('Root') %}
        <div class="content">
            <h4 class="title">试用期员工 试用期信息</h4>
            <div class="toolbar">
                <!--        Here you can write extra buttons/actions for the toolbar              -->
                <form method="post">
                    查询方式
                    <select name="info" required>
                        <option value="userID">员工号</option>
                        <option value="username">员工姓名</option>
                        <option value="departmentname">部门名称</option>
                        <option value="examine_result">状态</option>
                        <option value="startdate">开始时间</option>
                        <option value="enddate">结束时间</option>
                    </select>
                    <input type="text" name="date" autocomplete="off" required>
                    <input type="submit" name="submit" value="查询">
                </form>

            </div>
            {% if info == 'userID' or info == 'username' %}
                <div class="material-datatables">
                    <table id="datatables" class="table table-striped table-no-bordered table-hover"
                           style="width:100%;cellspacing:0">
                        <thead>
                        <tr>
                            <th>员工号</th>
                            <th>姓名</th>
                            <th>部门</th>
                            <th>开始时间</th>
                            <th>结束时间</th>
                            <th>考核评语</th>
                            <th>考核结果</th>
                            <th>处理日期</th>
                            <th>备注</th>
                            <th class="disabled-sorting text-right">操作</th>
                        </tr>
                        </thead>

                        <tbody>
                        <tr>
                            <td>{{ staffs.userID }}</td>
                            <td>{{ staffs.username }}</td>
                            <td>{{ departments.departmentname }}</td>
                            <td>{{ staff_probations.startdate }}</td>
                            <td>{{ staff_probations.enddate }}</td>
                            <td>{{ probations.examine_remark }}</td>
                            <td>{{ probations.examine_result }}</td>
                            <td>{{ probations.disposedate }}</td>
                            <td>{{ probations.remark }}</td>
                            <td class="text-right">
                                {% if probations.examine_result == None %}
                                    <a href="{{ url_for('write_probation',userID=staffs.userID) }}"
                                       class="btn btn-simple btn-info btn-icon like">添加</a>
                                {% else %}
                                    <a href="{{ url_for('change_probation',userID=staffs.userID) }}" class="btn btn-simple btn-info btn-icon like">修改</a>
                                {% endif %}
                            </td>
                        </tr>
                        </tbody>

                    </table>
                </div>
            {% else %}

                <div class="material-datatables">
                    <table id="datatables" class="table table-striped table-no-bordered table-hover"
                           style="width:100%;cellspacing:0">
                        <thead>
                        <tr>
                            <th>员工号</th>
                            <th>姓名</th>
                            <th>部门</th>
                            <th>开始时间</th>
                            <th>结束时间</th>
                            <th>考核评语</th>
                            <th>考核结果</th>
                            <th>处理日期</th>
                            <th>备注</th>
                            <th class="disabled-sorting text-right">操作</th>
                        </tr>
                        </thead>

                        <tbody>
                        {% for staff in staffs %}
                            {% for staff_probation in staff_probations %}
                                {% for noin in noins %}
                                        {% if staff.userID == staff_probation.userID and staff_probation.userID == noin.userID %}
                                            <tr>
                                                <td>{{ staff.userID }}</td>
                                                <td>{{ staff.username }}</td>

                                                {% if info == 'departmentname' %}
                                                    <td>{{ departments.departmentname }}</td>
                                                {% else %}
                                                    {% for department in departments %}
                                                        {% if staff.departmentID == department.departmentID %}
                                                            <td>{{ department.departmentname }}</td>
                                                        {% endif %}
                                                    {% endfor %}
                                                {% endif %}
                                                <td>{{ staff_probation.startdate }}</td>
                                                <td>{{ staff_probation.enddate }}</td>
                                                <td></td>
                                                <td></td>
                                                <td></td>
                                                <td></td>

                                                <td class="text-right">
                                                    <a href="{{ url_for('write_probation',userID=staff.userID) }}"
                                                       class="btn btn-simple btn-info btn-icon like">填写</a>
                                                </td>
                                            </tr>
                                        {% endif %}
                                {% endfor %}
                                {% for probation in probations %}
{#                                    {% if probations|length == 0 %}#}
{#                                        {% if staff.userID == staff_probation.userID %}#}
{#                                            <tr>#}
{#                                                <td>{{ staff.userID }}</td>#}
{#                                                <td>{{ staff.username }}</td>#}
{##}
{#                                                {% if info == 'departmentname' %}#}
{#                                                    <td>{{ departments.departmentname }}</td>#}
{#                                                {% else %}#}
{#                                                    {% for department in departments %}#}
{#                                                        {% if staff.departmentID == department.departmentID %}#}
{#                                                            <td>{{ department.departmentname }}</td>#}
{#                                                        {% endif %}#}
{#                                                    {% endfor %}#}
{#                                                {% endif %}#}
{#                                                <td>{{ staff_probation.startdate }}</td>#}
{#                                                <td>{{ staff_probation.enddate }}</td>#}
{#                                                <td></td>#}
{#                                                <td></td>#}
{#                                                <td></td>#}
{#                                                <td></td>#}
{##}
{#                                                <td class="text-right">#}
{#                                                    <a href="{{ url_for('write_probation',userID=staff.userID) }}"#}
{#                                                       class="btn btn-simple btn-info btn-icon like">填写</a>#}
{#                                                </td>#}
{#                                            </tr>#}
{#                                        {% endif %}#}
{#                                    {% else %}#}
                                        {% if  staff.userID == staff_probation.userID and staff.userID == probation.userID %}
                                            <tr>
                                                <td>{{ staff.userID }}</td>
                                                <td>{{ staff.username }}</td>

                                                {% if info == 'departmentname' %}
                                                    <td>{{ departments.departmentname }}</td>
                                                {% else %}
                                                    {% for department in departments %}
                                                        {% if staff.departmentID == department.departmentID %}
                                                            <td>{{ department.departmentname }}</td>
                                                        {% endif %}
                                                    {% endfor %}
                                                {% endif %}
                                                <td>{{ staff_probation.startdate }}</td>
                                                <td>{{ staff_probation.enddate }}</td>


                                                <td>{{ probation.examine_remark }}</td>
                                                <td>{{ probation.examine_result }}</td>
                                                <td>{{ probation.disposedate }}</td>
                                                <td>{{ probation.remark }}</td>
                                                <td class="text-right">
                                                    <a href="{{ url_for('change_probation',userID=staff.userID) }}" class="btn btn-simple btn-info btn-icon like">修改</a>
                                                </td>
                                            </tr>
                                        {% endif %}
{#                                    {% endif %}#}
                                {% endfor %}
                            {% endfor %}
                        {% endfor %}
                        </tbody>

                    </table>
                </div>


            {% endif %}
        </div>
    {% endif %}
{% endblock %}